#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) JoinQuant Development Team
# Author: Huayong Kuang <kuanghuayong@joinquant.com>

class Obj(object):

    def __init__(self):
        self.__v = None

    @property
    def _v(self):
        if self.__v is None:
            self.__v = 1
        raise AttributeError("test")
        # NOTE: 在 property 函数中，如果发生 AttributeError 异常时
        #  会尝试调用 __getattr__ 函数
        return self.__v

    def __getattr__(self, name):
        msg = "'{}' object has no attribute '{}'".format(
            self.__class__.__name__, name
        )
        raise AttributeError(msg)

    def get_v(self):
        return self._v

    def __repr__(self):
        return "Obj(v={})".format(self._v)


class SubObj(Obj):

    def __init__(self):
        super().__init__()


o = SubObj()
print(o.get_v())
print(o)
